//
// Created by fanghr on 17-12-24.
//

#ifndef PROJECT_IMU_ANGULARVELOCITY_H
#define PROJECT_IMU_ANGULARVELOCITY_H

#include "../../include.h"

class imu_angularVelocity {
public:
    struct table_t {
        friend class boost::serialization::access;

        uint16_t wx, wy, wz, t;

        template<class Archive>
        void serialize(Archive &ar, const unsigned int) {
            ar & wx;
            ar & wy;
            ar & wz;
        }
    };

private:
    friend class boost::serialization::access;

    template<class Archive>
    void serialize(Archive &ar, const unsigned int) {
        ar & table;
    }

    table_t table;
public:
    imu_angularVelocity() {}

    imu_angularVelocity(boost::array<uint8_t, 9> raw) {
        table.wx = (uint16_t) ((raw.at(1) << 8) | raw.at(0)) / (uint16_t) 32768 * (uint16_t) 2000;
        table.wy = (uint16_t) ((raw.at(3) << 8) | raw.at(2)) / (uint16_t) 32768 * (uint16_t) 2000;
        table.wz = (uint16_t) ((raw.at(5) << 8) | raw.at(4)) / (uint16_t) 32768 * (uint16_t) 2000;
        table.t = (uint16_t) ((raw.at(7) << 8) | raw.at(6)) / (uint16_t) 100;
    }

    table_t get() {
        return table;
    }
};

#endif //PROJECT_IMU_ANGULARVELOCITY_H
